<template>
    <div>
        <el-button type="primary" @click="addUser('/AddUser')">添加用户</el-button>
        <el-button type="danger" style="float:right;" @click="deleteUsers">点我批量删除</el-button>
        <el-table :data="tableData" style="width: 100%" height="345" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55">
            </el-table-column>
            <el-table-column fixed prop="id" label="id" width="150">
            </el-table-column>
            <el-table-column prop="userName" label="用户名" width="120">
            </el-table-column>
            <el-table-column prop="password" label="密码" width="120">
            </el-table-column>
            <el-table-column prop="realName" label="真实姓名" width="120">
            </el-table-column>
            <el-table-column prop="useType" label="用户类别" width="120">
            </el-table-column>
            <el-table-column prop="isScheduling" label="是否参与排班" width="120">
            </el-table-column>
            <el-table-column prop="docTitleID" label="医生职称" width="120">
            </el-table-column>
            <el-table-column prop="registLeID" label="挂号级别" width="120">
            </el-table-column>
            <el-table-column fixed="right" label="操作" width="100">
                <template slot-scope="scope">
                    <el-button @click="handleClick(scope.row)" type="text" size="small">删除</el-button>
                    <el-button type="text" size="small">编辑</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="block">
            <el-pagination @current-change="handleCurrentChange" :current-page.sync="currentPage" :page-size="pageSize"
                layout="total, prev, pager, next" :total="total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
import { deleteByIdsFun, getListFun,deleteByIdFun } from '@/CommonJs/RequestApi'
export default {
    name: "Workbench",
    data() {
        return {
            tableData: [{
                id: 1,
                realName: "扁鹊",
                password: "bianque123",
                userName: "bianque",
                useType: 3,
                registLeID: 1,
                deptID: 1,
                docTitleID: 81,
                isScheduling: '是',
                delMark: 1
            }],
            checked: '',
            total: 0,
            pageNum: 0, // 当前页 默认设值1
            pageSize: 5, // 每页显示条目 默认设置5
            currentPage: 0, //初始页
            selectListId: []
        }
    }, methods: {
        getList() {
            getListFun('user/findUserList',this.pageNum,this.count,'').then(response=>{
                console.log(response)
            })
        },

        handleCurrentChange(val) {
            this.currentPage = val;
                getListFun('user/get_user',{pageNum:(this.currentPage - 1)* this.pageSize,pageSize:this.pageSize,keywords:''}).then(response=>{
                    this.tableData = response.data.data
                })
        },
        addUser(val) {
            this.$router.push(val)
        },
        handleClick(row) {
            deleteByIdFun('user/delete_user',row.id).then(response=>{
                location.reload();
            })
        },
        handleSelectionChange(val) {
            this.selectListId.push(val[val.length - 1].id);
            //循环添加数组中最后一个的id给新数组
            console.log(this.selectListId);
        },
        deleteUsers() {
            deleteByIdsFun('user/delete_user_more',this.selectListId).then(response=>{
                location.reload();
            })
        }




    }, mounted() {
        this.tableData = []
        // const that = this;
        // this.$http({ url: 'http://localhost:4444/ssm_his/his/user/findUserList', params: { page: that.pageNum, count: that.pageSize, keywords: '' }, method: 'post' }).then((response) => {
        //     this.tableData = response.data.data
        // })
        getListFun('user/get_user',{pageNum:this.pageNum,pageSize:this.pageSize,keywords:''}).then(response=>{
                console.log(response)
                this.tableData = response.data.data
                this.total = response.data.count
            })
        
    }
}

</script>



<style scoped></style>